package dao;

import entity.Dept;
import org.springframework.jdbc.core.BeanPropertyRowMapper;

import java.util.List;
import java.util.Map;

public class DeptDao extends BaseDao{
    /**
     * 查询所有部门信息，部门id,部门名称，部门人数
     *
     * @return
     */
    public List<Map<String, Object>> findAllDept() {

        String sql = "select \n" +
                "d.id,\n" +
                "d.name, \n" +
                "count(u.dept_id) deptCount \n" +
                "from \n" +
                "dept d \n" +
                "LEFT JOIN user u on d.id=u.dept_id\n" +
                "GROUP BY \n" +
                "d.id";
        List<Map<String, Object>> deptMapList = jdbcTemplate.queryForList(sql);

        return deptMapList;

    }

    /**
     * 查询所有部门信息
     * @return
     */
    public List<Dept> findAll() {
        return jdbcTemplate.query("select * from dept",new BeanPropertyRowMapper<>(Dept.class));
    }
}
